<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<% String contextPath = request.getContextPath(); %>

<%@page import="com.infodms.dms.common.Constant"%>
<%@page import="java.util.List"%>
<%@page import="com.infodms.dms.po.TtAsWrRulePO"%>
<%@page import="com.infodms.dms.po.TtAsWrGamePO"%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <jsp:include page="${contextPath}/common/jsp_head_new.jsp" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>三包策略新增</title>
	<script type="text/javascript">
	    function doInit()
		{
		   loadcalendar();
		}
	</script>
</head>
<body onload="doInit();">
<div class="navigation"><img src="<%=contextPath%>/img/nav.gif" />当前位置：售后服务管理&gt;索赔基本数据&gt;三包策略维护
<%
	List ruleList = (List)request.getAttribute("ruleList");
	List sysRuleList = (List)request.getAttribute("sysRuleList");
%>

<select id="RULE_ID" style="display:none"><%-- 业务规则 --%>
	<% 
	if(ruleList!=null && ruleList.size()>0){
	%>
	<%
	for(int i=0;i<ruleList.size();i++){
		TtAsWrRulePO rulePO = (TtAsWrRulePO)ruleList.get(i);
	%>
	<option value="<%=rulePO.getId()%>"><%=rulePO.getRuleName()%></option>
	<%		}%>
	<% } else { %>
	<option value="">请先维护业务类型三包规则</option>
	<% } %>
</select>
<select id="SYS_RULE_ID" style="display:none"><%-- 系统规则 --%>
	<% 
	if(sysRuleList!=null && sysRuleList.size()>0){
	%>
	<%
	for(int i=0;i<sysRuleList.size();i++){
		TtAsWrRulePO rulePO = (TtAsWrRulePO)sysRuleList.get(i);
	%>
	<option value="<%=rulePO.getId()%>"><%=rulePO.getRuleName()%></option>
	<%		}%>
	<% } else { %>
	<option value="">请先维护业务类型三包规则</option>
	<% } %>
</select>
</div>
	<form action="<%=contextPath%>/claim/basicData/TreeGuaranteesStrategy/addStrategy.do" method="post" name="fm" id="fm">
	    <table border="0" width="100%">
	    <tr>
		    <td>
		  		<!-- 三包策略基本信息  -->
				<table class="table_info">
				    <tr>
			           <th colspan="4">
			           	<img class="nav" src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('baseTab')">基本信息</a>
			           </th>
		            </tr>
		        </table>
			    <!-- 三包策略基本信息(新增时)  -->
				<table class="table_edit">
					<tr>
						<td align="right">三包策略类型：</td>
						<td>
							<script type="text/javascript">
								 genSelBoxExp("GAME_TYPE",<%=Constant.GAME_TYPE%>,"<%=Constant.GAME_TYPE_02%>",false,"short_sel"," onchange=\"changeGameType(this)\"","false",'');
						    </script>
						</td>
						<td align="right">三包策略状态：</td>
						<td>
							<script type="text/javascript">
								 genSelBoxExp("STATUS",<%=Constant.STATUS%>,"",false,"short_sel","","false",'');
						    </script>
						</td>
					</tr>
					<tr>
						<td align="right">三包策略代码：</td>
						<td>
							<input type='text' name='STRATEGY_CODE' id='STRATEGY_CODE' 
							class="middle_txt" datatype="0,is_null,20"/>
						</td>
						<td align="right">三包策略名称：</td>
						<td>
							<input type='text' name='STRATEGY_NAME' id='STRATEGY_NAME'
							class="middle_txt" datatype="0,is_null,60"/>
						</td>
					</tr>
				
					<tr>
						<td align="right">免费保养次数：</td>
						<td>
						    <input type='text' name='GUARANTEE_COUNT' id='GUARANTEE_COUNT' onchange="dyncCreateGuarante('dyncGuarantee',this);"
							class="short_txt" datatype="0,isDigit,10"/>
						</td>
						<td align="right">三包规则：</td>
						<td>
						    <select name="GUARANTEE_RULE_ID" id="GUARANTEE_RULE_ID" 
						    	class="long_sel">
							<% 
								if(ruleList!=null && ruleList.size()>0){
							%>
							<%
									for(int i=0;i<ruleList.size();i++){
										TtAsWrRulePO rulePO = (TtAsWrRulePO)ruleList.get(i);
							%>
									<option value="<%=rulePO.getId()%>"><%=rulePO.getRuleName()%></option>
							<%		}%>
							<% } else { %>
								<option value="">请先维护业务类型三包规则</option>
							<% } %>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">三包策略开始时间：</td>
						<td>
							<input type="text" name="START_TIME" id="START_TIME"
				             value="" type="text" class="short_txt" 
				             datatype="0,is_date,10" group="START_TIME,END_TIME" 
				             hasbtn="true" callFunction="showcalendar(event, 'START_TIME', false);"/>
						</td>
						<td align="right">三包策略结束时间：</td>
						<td>
							<input type="text" name="END_TIME" id="END_TIME"
					             value="" type="text" class="short_txt" 
					             datatype="0,is_date,10" group="START_TIME,END_TIME" 
					             hasbtn="true" callFunction="showcalendar(event, 'END_TIME', false);"/>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top">备注：</td>
						<td colspan="3">
							<textarea id="REMARK" name="REMARK" rows="3" cols="80" datatype="1,is_textarea,1000"></textarea>
						</td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td>
	                <table class="table_info" >
				       <tr>
				           <th>
				           	<img class="nav" src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('guaranteeTab')">保养费用</a>
				           </th>
			           </tr>
			        </table>
					<table class="table_edit" border="0" cellpadding="0" cellspacing="0">
				   		<tr>
				   			<td align="center">
				   				<div id="dyncGuarantee">
							    </div>
							</td>
					    </tr>
					    <tr>
							<td align="center">
								<!-- 三包策略ID -->
				       		    <input type="button" name="bt_add" class="normal_btn" 
								     onclick="frmSubmitConfirm();" value="新增"/>&nbsp;&nbsp;
								<input type="button" name="bt_back" class="normal_btn" 
								    onclick="history.back();" value="返回"/>
							</td>
					    </tr>
			 	     </table>
				</td>
			</tr>
		</table>
	</form>
	
	<script type="text/javascript">
		function frmSubmitConfirm(){
			var remarkValue = $('REMARK').value;
			if(remarkValue && remarkValue.length>500){
				alert("备注信息长度不能超过 500!");
				return;
			}
			if(submitForm('fm')){//查询表单数据格式
				//var nowDate = (new Date()).Format("yyyy-MM-dd");
			   //var startTime = document.getElementById('START_TIME').value;
			   // if(!checkDate(startTime,nowDate)){//选择三包策略开始时间必须大于当前时间    
			    	MyConfirm("是否确认新增？",frmSubmit,[null]);
			    //}else{
				    //MyAlert("三包策略开始日期必须大于当前日期！");
			    //}
			}
		}

		//保存保修费用(提示错误信息，但显示慢)
		function saveGuarantee(){
			makeNomalFormCall('<%=contextPath%>/claim/basicData/TreeGuaranteesStrategy/addStrategy.do',showResult,'fm','');
		}

		function showResult(){
			//不做处理
		}

		//使用Form提交的方式保存,不能提示错误信息
		function frmSubmit(){
			var frm = document.getElementById('fm');
			frm.submit();
		}

		//动态生成保养费用列表
		function dyncCreateGuarante(tbodyId,count){
			var varTbodyId = document.getElementById(tbodyId);
			var guaranteCount = count.value;
			if(varTbodyId!=null && varTbodyId!='undefined'){
				var content = '';
				for(var i=0;i<guaranteCount;i=i+2){
					content = content + getDyncContent(i,'');
			        if((i+1)<guaranteCount){
			        	content = content + getDyncContent((i+1),'');
			        }
					content = "<tr>" + content + "</tr>";
				}
				varTbodyId.innerHTML = '<table class="table_edit">' + content + '</table>';
				for(var i=0;i<guaranteCount;i++){
					setMustStyle([document.getElementById('GUARANTEE_AMOUNT'+i)]);
				}
			}
		}

		function getDyncContent(index,value){
			var content = '<td align="right">第'+(index+1)+'次保养费用(元)：</td>'+
			'<td align="left">'+
				'<input type="text" datatype="0,is_double,20" decimal="2" name="GUARANTEE_AMOUNT'+index+'" id="GUARANTEE_AMOUNT'+index+'"'+' value="'+value+'"/>'+
			'</td>';
			return content;
		}

		function changeGameType(gametype){

			var selectedValue = gametype.options[gametype.selectedIndex].value;
			var target = '<%=Constant.GAME_TYPE_01%>';
			var content = '';
			if(target==selectedValue){
				content = $('SYS_RULE_ID').innerHTML;
			}else{
				content = $('RULE_ID').innerHTML;
			}
			$('GUARANTEE_RULE_ID').outerHTML = '<select name="GUARANTEE_RULE_ID" id="GUARANTEE_RULE_ID" class="long_sel">' + content + '</select>';
		}
	</script>
</body>
</html>